package cn.gemiman.daoyi.module.cms.dal.mysql.appsite;

import java.util.*;

import cn.gemiman.daoyi.framework.common.pojo.PageResult;
import cn.gemiman.daoyi.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.gemiman.daoyi.framework.mybatis.core.mapper.BaseMapperX;
import cn.gemiman.daoyi.module.cms.dal.dataobject.appsite.AppSiteDO;
import org.apache.ibatis.annotations.Mapper;
import cn.gemiman.daoyi.module.cms.controller.admin.appsite.vo.*;
import org.apache.ibatis.annotations.Update;

/**
 * 站点 Mapper
 *
 * @author 道一源码
 */
@Mapper
public interface AppSiteMapper extends BaseMapperX<AppSiteDO> {

    default PageResult<AppSiteDO> selectPage(AppSitePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AppSiteDO>()
                .eqIfPresent(AppSiteDO::getTerminalType, reqVO.getTerminalType())
                .eqIfPresent(AppSiteDO::getAppId, reqVO.getAppId())
                .likeIfPresent(AppSiteDO::getAppName, reqVO.getAppName())
                .betweenIfPresent(AppSiteDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(AppSiteDO::getUserType, reqVO.getUserType())
                .eqIfPresent(AppSiteDO::getUserId, reqVO.getUserId())
                .eqIfPresent(AppSiteDO::getStatus, reqVO.getStatus())
                .eqIfPresent(AppSiteDO::getApproveStatus, reqVO.getApproveStatus())
                .likeIfPresent(AppSiteDO::getUserNickname, reqVO.getUserNickname())
                .likeIfPresent(AppSiteDO::getBindDomain, reqVO.getBindDomain())
                .orderByDesc(AppSiteDO::getId));
    }

    @Update("update cms_app_site set view_times = view_times + 1 where app_id = #{appId}")
    void addAppSiteView(String appId);
}
